
//提交留言
function submitComment() {
	var guestName = $("input[id='guestName']").val();
	var guestPhone = $("input[id='guestPhone']").val();
	var content = $("textarea[id='content']").val();
	
	if(valid() == true) {
		$.post("SubmitComment", {caseId : $userCurrentCaseId, guestName: guestName, guestPhone: guestPhone, content: content}, function(text) {
			var data = (new Function("return "+text))();
			if (data.status.indexOf('成功')) {
				alert("留言成功，通过审核后方可显示。");
				clearForm();
			} else {
				alert("留言失败！");
			}
		});
	}
}

//清除信息
function clearForm() {
	$("input[id='guestName']").val("");
	$("input[id='guestName']").focus();
	$("#guestPhone").val("");
	$("textarea[id='content']").val("");
}

//验证留言输入框
function valid() {	
	// 验证用户名
	var guestName = $("input[id='guestName']").val();
	guestName = $.trim(guestName);
	if (guestName==null || guestName.length==0){
		alert("请输入姓名！");
		return false;
	}
	
	// 验证手机号
	var guestPhone = $("#guestPhone").val();
	guestPhone = $.trim(guestPhone);
	if (guestPhone==null || guestPhone.length==0){
		alert("请输入手机号码！");
		return false;
	}
	var patrn = /^(13[0-9]{9})|(15[89][0-9]{8})$/;
	if (!patrn.exec(guestPhone)){
		alert("手机号码格式不对，请重新输入！");
		return false;
	}
	
	// 验证留言内容
	var content = $("textarea[id='content']").val();
	content = $.trim(content);
	if (content==null || content.length==0){
		alert("请输入留言内容！");
		return false;
	}
	
	return true;
}
